package main

import (
	"encoding/json"
	"fmt"
	"github.com/tealeg/xlsx"
	"log"
)

func main() {
	excelFileName := `C:\Users\admin\Documents\Tencent Files\290198252\FileRecv\monster.xlsx`
	xlFile, err := xlsx.OpenFile(excelFileName)
	if err != nil {
		log.Print(err.Error())
	}
	data2json := map[string]interface{}{}
	data2JsonKey := map[int] string{}
	data2JsonValue := map[int] interface{}{}
	for _, sheet := range xlFile.Sheets {
		for n, row := range sheet.Rows {
			if n == 0{
				continue
			}
			if n == 1{
				for i, cell := range row.Cells {
					text := cell.String()
					fmt.Printf("%s    ", text)
					data2JsonKey[i] = text
				}
			}
			if n == 2{
				for i, cell := range row.Cells {
					text := cell.String()
					fmt.Printf("%s    ", text)
					data2JsonValue[i] = text
				}
			}
			fmt.Printf("\r\n")
		}
	}
	for k,v := range data2JsonKey{
		data2json[v] = data2JsonValue[k]
	}
	log.Print(data2json)
	bs,e := json.Marshal(data2json)
	if nil != e{
		log.Print(e.Error())
	}
	log.Print(string(bs))
}